import { HistoryRoutes } from '@/interface/route/historyRoutes'
import { defineStore } from 'pinia'

export const useHistoryStore = defineStore(
    'history',
    () => {
        const historyRoutes = ref<HistoryRoutes[]>([
            {
                path: '/',
                name: '首页',
                isFixed: true,
                isAllowDelete: false
            },
            {
                path: '/',
                name: '首页1',
                isFixed: false,
                isAllowDelete: true
            },
            {
                path: '/',
                name: '首页1',
                isFixed: false,
                isAllowDelete: true
            },
            {
                path: '/',
                name: '首页1',
                isFixed: false,
                isAllowDelete: true
            },
            {
                path: '/',
                name: '首页1',
                isFixed: false,
                isAllowDelete: true
            },
            {
                path: '/',
                name: '首页1',
                isFixed: false,
                isAllowDelete: true
            },
            {
                path: '/',
                name: '首页1',
                isFixed: false,
                isAllowDelete: true
            },
            {
                path: '/',
                name: '首页1',
                isFixed: false,
                isAllowDelete: true
            },
            {
                path: '/',
                name: '首页1',
                isFixed: false,
                isAllowDelete: true
            },
            {
                path: '/',
                name: '首页1',
                isFixed: false,
                isAllowDelete: true
            },
            {
                path: '/',
                name: '首页1',
                isFixed: false,
                isAllowDelete: true
            }
        ])

        const setHistoryRoute = (route:HistoryRoutes) => {
            let index = historyRoutes.value.findIndex(item => item.name === route.name)
            if (index === -1) {
                historyRoutes.value.push(route)
            }
        }
        const deleteHistoryRoute = (route:HistoryRoutes) => {
            let index = historyRoutes.value.findIndex(item => item.name === route.name)
            if (index !== -1) {
                historyRoutes.value.splice(index, 1)
            }
        }

        return {
            historyRoutes,
            setHistoryRoute,
            deleteHistoryRoute
        }
    }
)